package org.hxzon.workeasy.pages.user;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.workeasy.model.EasyUzer;
import org.hxzon.workeasy.pages.base.MyBasePage;
import org.hxzon.workeasy.permissions.UserViewPermissions;
import org.hxzon.workeasy.service.EasyUserService;

public class ViewUser extends MyBasePage {
    @Inject
    private EasyUserService userSer;
    @Property
    private EasyUzer user;

    public Object initialize(String id) {
        init(id);
        return this;
    }

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init(String id) {
        new UserViewPermissions().check(null, getVisitor());
        user = userSer.findById(id);
        return null;
    }

    @OnEvent(value = EventConstants.PASSIVATE)
    Object onPassivate() {
        return user.getId();
    }
}
